package com.wutuo.school.provider.dao;


import com.wutuo.school.provider.domain.School;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * 校区 Dao 层
 *
 * @author lvh
 * @version 1.0
 */

public class BaseSchoolSqlProvider implements java.io.Serializable {

    public String insertSelective(School record) {
        BEGIN();
        INSERT_INTO("school");
        insertKey(record);
        return SQL();
    }

    public void insertKey(School record) {

        if (record.getSchoolName() != null) {
            VALUES("school_name", "#{schoolName,jdbcType=VARCHAR}");
        }
        if (record.getPhone() != null) {
            VALUES("phone", "#{phone,jdbcType=VARCHAR}");
        }
        if (record.getLogo() != null) {
            VALUES("logo", "#{logo,jdbcType=VARCHAR}");
        }
        if (record.getAddress() != null) {
            VALUES("address", "#{address,jdbcType=VARCHAR}");
        }
        if (record.getProvince() != null) {
            VALUES("province", "#{province,jdbcType=VARCHAR}");
        }
        if (record.getCity() != null) {
            VALUES("city", "#{city,jdbcType=VARCHAR}");
        }
        if (record.getCounty() != null) {
            VALUES("county", "#{county,jdbcType=VARCHAR}");
        }
        if (record.getCreateBy() != null) {
            VALUES("create_by", "#{createBy,jdbcType=BIGINT}");
        }
        if (record.getCreateDate() != null) {
            VALUES("create_date", "#{createDate,jdbcType=DATE}");
        }
        if (record.getUpdateBy() != null) {
            VALUES("update_by", "#{updateBy,jdbcType=BIGINT}");
        }
        if (record.getUpdateDate() != null) {
            VALUES("update_date", "#{updateDate,jdbcType=DATE}");
        }
        if (record.getRemarks() != null) {
            VALUES("remarks", "#{remarks,jdbcType=VARCHAR}");
        }
        if (record.getDelFlag() != null) {
            VALUES("del_flag", "#{delFlag,jdbcType=VARCHAR}");
        }
    }

    public String updateByPrimaryKeySelective(School record) {
        BEGIN();
        UPDATE("school");
        updateKey(record);
        WHERE("id = #{id,jdbcType=BIGINT}");
        return SQL();
    }

    public void updateKey(School record) {
        if (record.getId() != null) {
            SET("id = #{id,jdbcType=BIGINT}");
        }
        if (record.getSchoolName() != null) {
            SET("school_name = #{schoolName,jdbcType=VARCHAR}");
        }
        if (record.getPhone() != null) {
            SET("phone = #{phone,jdbcType=VARCHAR}");
        }
        if (record.getLogo() != null) {
            SET("logo = #{logo,jdbcType=VARCHAR}");
        }
        if (record.getAddress() != null) {
            SET("address = #{address,jdbcType=VARCHAR}");
        }
        if (record.getProvince() != null) {
            SET("province = #{province,jdbcType=VARCHAR}");
        }
        if (record.getCity() != null) {
            SET("city = #{city,jdbcType=VARCHAR}");
        }
        if (record.getCounty() != null) {
            SET("county = #{county,jdbcType=VARCHAR}");
        }
        if (record.getCreateBy() != null) {
            SET("create_by = #{createBy,jdbcType=BIGINT}");
        }
        if (record.getCreateDate() != null) {
            SET("create_date = #{createDate,jdbcType=DATE}");
        }
        if (record.getUpdateBy() != null) {
            SET("update_by = #{updateBy,jdbcType=BIGINT}");
        }
        if (record.getUpdateDate() != null) {
            SET("update_date = #{updateDate,jdbcType=DATE}");
        }
        if (record.getRemarks() != null) {
            SET("remarks = #{remarks,jdbcType=VARCHAR}");
        }
        if (record.getDelFlag() != null) {
            SET("del_flag = #{delFlag,jdbcType=VARCHAR}");
        }
    }
}